﻿Imports ADOEntityKYC
Imports System.Data
Imports Microsoft.VisualBasic
Imports System.Web.Configuration
Imports System.Data.SqlClient
Imports System.Web.UI.WebControls.GridView
Imports DevExpress.Web.ASPxEditors
Partial Class Administrator_TranOfMonth
    Inherits Web.UI.BasePage
    Private Const strMenuCode As String = "M75"
    Dim sAmountEntity As KYCEntities
    Dim dsAmount As New DataSet
    Dim clsQuery As clsDatabase
    Dim clsDataTable As New clsLINQToDataTable
    Dim intBeforeItemIndex As Integer
    Dim clsSessionMenuRight As clsSessionMenuRight = New clsSessionMenuRight
    Dim strMsg As String = ""

#Region " Even Page "

    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
        'lblAmountCode.Text = "รหัสอำเภอ" & " : "
        'lblAmountName.Text = "ชื่ออำเภอ" & " : "
        lblSEQ.Text = "ลำดับ :"
        lblDiscription.Text = "รายละเอียด :"
        lblProduct.Text = "จังหวัด" & " : "
        lblActive.Text = "สถานะการใช้งาน" & " : "
        rbtACTIVE.Text = "ใช้งาน"
        rbtDeACTIVE.Text = "ไม่ใช้งาน"
        btnSearch.Text = Resources.resButton.btnSearch
        btnAdd.Text = Resources.resButton.btnAdd
        btnModify.Text = Resources.resButton.btnModify
        btnDelete.Text = Resources.resButton.btnDelete
        btnClear.Text = Resources.resButton.btnClear
        btnPrint.Text = Resources.resButton.btnPrint
        lblMsg.Text = Resources.resMessageAlert.alertEmptyGrid
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            chkIsLogin()
            clsSessionMenuRight = Session("clsMenuRight")

            If (Not IsPostBack) Then
                setUserRightButton()
                CreateControlMP()
                setButton(1)
                loadDataToDropDown()
                SetControl_Button()
                'Else
                'dsAmount = Session("dsTblMaster")
                '    gvTranOfMonth.DataSource = dsAmount.Tables("sAmount")
                gvTranOfMonth.DataBind()
            End If
        Catch ex As Exception

        End Try
    End Sub

    Protected Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Unload
        Session("dsTblMaster") = dsAmount
    End Sub

#End Region

#Region "SetForm"

    Sub CreateControlMP()

        Dim lblForm As Label = CType(Master.FindControl("lblForm"), Label)
        lblForm.Text = "อำเภอ"
    End Sub

    Sub SetControl_Button()
        btnSearch.Attributes.Add("onclick", "NoDoubleSubmit();")
        btnModify.Attributes.Add("onclick", "NoDoubleSave();")
        btnAdd.Attributes.Add("onclick", "NoDoubleSave();")
        btnDelete.Attributes.Add("onclick", "NoDoubleSave();")
    End Sub
#End Region

#Region " Even Button "

    Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click
        IsDataBind()
        SaveLogSearch()
        gvTranOfMonth.Visible = True
    End Sub

    Protected Sub btnAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        ' Response.Redirect("Department.aspx?Status=Add")
        Try
            If chkBeforeSave(False) Then
                Dim Amounts As New MAMOUNT_PER_MONTH
                Dim db = New KYCEntities

                Amounts.SEQ = txtSEQ.Text
                Amounts.DESCRIPTION = txtDiscription.Text
                Amounts.PRODUCTCODE = ddlProduct.SelectedItem.Value
                If (rbtACTIVE.Checked = True) Then
                    Amounts.ACTIVE = "Y"
                Else
                    Amounts.ACTIVE = "N"
                End If
                'sAmountEntity.AddToREFERENCE_CODE_TABLE(sAmount)
                sAmountEntity.SaveChanges()
                sAmountEntity.Dispose()
                sAmountEntity = Nothing
                SaveLogNew()
                db.AddToMAMOUNT_PER_MONTH(Amounts)
                db.SaveChanges()
                ddlProduct.SelectedIndex = 0
                txtSEQ.Text = ""
                txtDiscription.Text = ""
                IsDataBind()
                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" + Resources.resMsgKYC.msgSave + "')", True)
            Else

                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" + strMsg + "')", True)

            End If
        Catch ex As System.Data.UpdateException

            Dim codeError() As String = ex.InnerException.Message.Split(":")
            If codeError(0) = "ORA-00001" Then
                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('ไม่สามารถเพิ่มได้ เนื่องจากรหัสนี้มีการนำมาใช้ในระบบแล้ว')", True)
            Else
                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" + ex.InnerException.Message + "')", True)
            End If
            WriteError(ex, "btnAdd_Click", "Amount")
        Catch ex As Exception
            WriteError(ex, "btnAdd_Click", "Amount")
            ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('บันทึกผิดพลาด')", True)

        End Try
    End Sub
    Protected Sub btnModify_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnModify.Click
        Dim state As String
        If (rbtACTIVE.Checked = True) Then
            state = "Y"
        Else
            state = "N"
        End If
        'Try
        'If chkBeforeSave(True) Then
        Dim db As New KYCEntities
        Dim mm As New MAMOUNT_PER_MONTH
        Dim kk As String = gvTranOfMonth.Rows(gvTranOfMonth.SelectedIndex).Cells(1).Text
        ' Query the database for the row to be updated. 
        Dim ordQuery = (From ord In db.MTRANS_PER_MONTH
                        Join mpro In db.MPRODUCT On mpro.PRODUCTCODE Equals ord.PRODUCTCODE
                         Where ord.SEQ = kk And mpro.PRODUCTNAME.Contains(HiddenField1.Value)
                        Select ord).First()
        ordQuery.DESCRIPTION = txtDiscription.Text
        ordQuery.ACTIVE = state
        db.SaveChanges()
        SaveLogEdit()
        txtSEQ.Text = ""
        txtDiscription.Text = ""
        ddlProduct.SelectedIndex = 0
        IsDataBind()
        'reset()

        ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" + Resources.resMsgKYC.msgSave + "')", True)

    End Sub

    Protected Sub btnDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDelete.Click
        Dim db As New KYCEntities
        Dim kk = gvTranOfMonth.Rows(gvTranOfMonth.SelectedIndex).Cells(1).Text

        Dim Query = (From i In db.MTRANS_PER_MONTH
                     Where i.SEQ = kk And i.PRODUCTCODE = HiddenField2.Value
                     Select i).FirstOrDefault()
        'Try
        db.DeleteObject(Query)
        db.SaveChanges()
        ddlProduct.SelectedIndex = 0
        txtSEQ.Text = ""
        txtDiscription.Text = ""
        rbtACTIVE.Checked = False
        rbtDeACTIVE.Checked = False
        IsDataBind()
        'Catch ex As System.Data.UpdateException
        '    Dim codeError() As String = ex.InnerException.Message.Split(":")
        '    If codeError(0) = "ORA-02292" Then
        '        ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('ไม่สามารถลบได้ เนื่องจากมีการนำมาใช้ในระบบแล้ว')", True)
        '    Else
        '        ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" + ex.InnerException.Message + "')", True)
        '    End If
        '    WriteError(ex, "btnDelete_Click", "Amount")
        'Catch ex As Exception
        '    ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" + strMsg + "')", True)
        '    'ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" + Resources.resError.errorMessage + "')", True)
        '    WriteError(ex, "btnDelete_Click", "Amount")
        'End Try

    End Sub

    Protected Sub btnClear_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnClear.Click
        clear()
    End Sub
    Protected Sub btnPrint_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPrint.Click
        Dim active As String = ""
        If (rbtACTIVE.Checked) Then
            active = "Y"
        ElseIf rbtDeACTIVE.Checked Then
            active = "N"
        End If
        Dim param As String = "{ 'AmountCode' : '" & txtSEQ.Text & "'," _
                                & "'rptType' : '216'," _
                           & "'AmountName' : '" & txtDiscription.Text & "'," _
                            & "'ProvinceCode' : '" & ddlProduct.Value & "'," _
                          & "'ACTIVE' : '" & active & "'}"

        'ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType, "key", "OpenWindowWithPost('../Form/frmPrintRptMasterRDLC.aspx','width=1000,height=600,left=100,top=100,resizable=yes,scrollbars=yes','Report', " + param + ");", True)
        ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType, "key", "OpenWindowWithPost('../Form/frmPrintRptMaster.aspx','width=1000,height=600,left=100,top=100,resizable=yes,scrollbars=yes','Report', " + param + ");", True)
        SaveLogPrint()
    End Sub

#End Region

#Region "Even GridView"

    Protected Sub gvTranOfMonth_PageIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles gvTranOfMonth.PageIndexChanged

    End Sub

    Protected Sub gvTranOfMonth_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gvTranOfMonth.PageIndexChanging
        gvTranOfMonth.PageIndex = e.NewPageIndex
        gvTranOfMonth.DataBind()
        IsDataBind()
    End Sub
    Protected Sub gvTranOfMonth_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvTranOfMonth.RowDataBound
        If (e.Row.RowType.ToString = "DataRow") Then
            Dim active As String = "ไม่ใช้งาน"

            Dim lblActive As Label = CType(e.Row.FindControl("grd_lbl_ACTIVE"), Label)
            Dim hidActive As HiddenField = CType(e.Row.FindControl("grd_hid_ACTIVE"), HiddenField)
            If (DataBinder.Eval(e.Row.DataItem, "ACTIVE") IsNot Nothing) Then
                If (DataBinder.Eval(e.Row.DataItem, "ACTIVE").ToString() = "Y") Then
                    active = "ใช้งาน"
                End If

                hidActive.Value = DataBinder.Eval(e.Row.DataItem, "ACTIVE").ToString()
            End If
            lblActive.Text = active
        End If

    End Sub

    Protected Sub gvTranOfMonth_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles gvTranOfMonth.SelectedIndexChanged

        Try
            'If (gvAmountOfMonth.SelectedIndex = intBeforeItemIndex) Then
            '    clearGvIndex()
            '    reset()

            btnModify.Text = "แก้ไข"
            'Else
            btnModify.Text = "บันทึก"
            setButton(2)
            txtSEQ.Text = gvTranOfMonth.Rows(gvTranOfMonth.SelectedIndex).Cells(1).Text
            ddlProduct.Text = gvTranOfMonth.Rows(gvTranOfMonth.SelectedIndex).Cells(2).Text
            txtDiscription.Text = gvTranOfMonth.Rows(gvTranOfMonth.SelectedIndex).Cells(3).Text
            HiddenField1.Value = gvTranOfMonth.Rows(gvTranOfMonth.SelectedIndex).Cells(2).Text
            HiddenField2.Value = ddlProduct.SelectedItem.Value
            ddlProduct.Enabled = False
            txtSEQ.Enabled = False
            Dim ds2 As HiddenField = CType(gvTranOfMonth.Rows(gvTranOfMonth.SelectedIndex).FindControl("grd_hid_ACTIVE"), HiddenField)
            If (ds2.Value = "Y") Then
                rbtACTIVE.Checked = True
            Else
                rbtDeACTIVE.Checked = True
            End If

            btnDelete.Attributes.Add("onclick", "return confirm('" + String.Format(Resources.resValidate.confirmDelete, _
                       IIf(gvTranOfMonth.SelectedIndex = -1, "", gvTranOfMonth.Rows(gvTranOfMonth.SelectedIndex).Cells(2).Text)) + "');")
            'End If
        Catch ex As Exception
            WriteError(ex, "gvProvince_SelectedIndexChanged", "Amount")
        End Try

    End Sub
    Protected Sub gvAmountOfMonth_SelectedIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSelectEventArgs) Handles gvTranOfMonth.SelectedIndexChanging
        'txtSEQ.Text = Me.gvAmountOfMonth.SelectedRow.ToString()
        'txtDiscription.Text = gvAmountOfMonth.Rows(gvAmountOfMonth.SelectedIndex).Cells(3).Text
        ' intBeforeItemIndex = gvAmountOfMonth.SelectedIndex
    End Sub

    Public Sub gvTranOfMonth_SelectedIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSelectEventArgs) Handles gvTranOfMonth.SelectedIndexChanging
        'gvTranOfMonth.PageIndex = e.NewSelectedIndex
        'gvTranOfMonth.DataBind()
        'intBeforeItemIndex = gvTranOfMonth.SelectedIndex
    End Sub
    Protected Sub gvTranOfMonth_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles gvTranOfMonth.Sorting
        Dim dt = TryCast(dsAmount.Tables("sAmount"), DataTable)

        If dt IsNot Nothing Then

            'Sort the data.
            dt.DefaultView.Sort = e.SortExpression & " " & GetSortDirection(e.SortExpression)
            gvTranOfMonth.DataSource = dsAmount.Tables("sAmount")
            gvTranOfMonth.DataBind()

        End If
    End Sub

#End Region

#Region " Function"

    Private Sub setUserRightButton()
        Dim col As New Collection
        col.Add(btnSearch, statusbtn.Query.ToString)
        col.Add(btnAdd, statusbtn.Add.ToString)
        col.Add(btnModify, statusbtn.Modify.ToString)
        col.Add(btnDelete, statusbtn.delete.ToString)
        setBtnToUserRight(col, strMenuCode, clsSessionMenuRight.getDsMenuRight)

    End Sub
    Private Function chkAmountUse() As Boolean
        '  
        Dim DepC As String = gvTranOfMonth.Rows(gvTranOfMonth.SelectedIndex).Cells(1).Text
        'Return clsValidateData.ChkAmountUse(DepC)
        'End If
        Return 0
    End Function
    Private Function chkBeforeDelete() As Boolean
        Dim result As Boolean = True
        If (chkAmountUse()) Then
            result = False
            strMsg = "อำเภอนี้ถูกใช้งานแล้วไม่สามารถลบได้" & "\n"
        End If
        Return result

    End Function

    Private Sub IsDataBind()
        Try
            sAmountEntity = New KYCEntities
            clsDataTable = New clsLINQToDataTable
            HiddenField1.Value = ddlProduct.SelectedItem.Value
            If dsAmount.Tables.Contains("sAmount") Then
                dsAmount.Tables.Clear()
            End If
            Dim qryDis = From Amount In sAmountEntity.MTRANS_PER_MONTH
                         From ProductName In sAmountEntity.MPRODUCT Where ProductName.PRODUCTCODE = Amount.PRODUCTCODE
                        Order By Amount.SEQ
                        Select Amount.SEQ, Amount.DESCRIPTION, Amount.ACTIVE, Amount.PRODUCTCODE, ProductName.PRODUCTNAME

            If Not (ddlProduct.SelectedItem.Value = 0) Then
                qryDis = qryDis.Where(Function(Dis) Dis.PRODUCTCODE = CStr(ddlProduct.SelectedItem.Value))
            End If

            If Not (txtSEQ.Text = "") Then
                qryDis = qryDis.Where(Function(Dis) Dis.SEQ = CInt(txtSEQ.Text))
            End If

            If Not (txtDiscription.Text = "") Then
                qryDis = qryDis.Where(Function(Dis) Dis.DESCRIPTION.Contains(txtDiscription.Text))
            End If
            If (rbtACTIVE.Checked) Then
                qryDis = qryDis.Where(Function(Pro) Pro.ACTIVE = "Y")
            ElseIf (rbtDeACTIVE.Checked) Then
                qryDis = qryDis.Where(Function(Pro) Pro.ACTIVE = "N")
            End If

            'dsAmount.Tables.Add(clsDataTable.LINQToDataTable((qryDis).AsEnumerable().OrderBy(Function(x) x.REF_CODE, StringComparer.CurrentCulture), "sAmount").Copy)

            If (qryDis.Count = 0) Then
                lblMsg.Visible = True
                lblTotal.Text = ""
            Else
                lblMsg.Visible = False
                lblTotal.Text = "จำนวนรายการทั้งหมด " + qryDis.Count.ToString + " รายการ "

            End If

            gvTranOfMonth.DataSource = qryDis.ToList()
            gvTranOfMonth.DataBind()
            sAmountEntity.Dispose()
        Catch ex As Exception
            WriteError(ex, "IsDataBind", "qryDis")

        End Try
    End Sub
    Private Function CheckDupplication(ByVal chkModifly As Boolean) As Boolean
        Dim Check As Boolean = False
        Try
            sAmountEntity = New KYCEntities
            clsDataTable = New clsLINQToDataTable
            If dsAmount.Tables.Contains("sAmount") Then
                dsAmount.Tables.Clear()
            End If
            Dim qryPro = From Amount In sAmountEntity.MAMOUNT_PER_MONTH
                         Where Amount.SEQ = ddlProduct.SelectedItem.Value And Amount.DESCRIPTION = txtDiscription.Text.Trim()
                        Order By Amount.SEQ
                        Select Amount.SEQ, Amount.DESCRIPTION

            dsAmount.Tables.Add(clsDataTable.LINQToDataTable(qryPro, "sAmount").Copy)

            If Not (chkModifly) Then
                If (qryPro.ToList.Count > 0) Then
                    Check = True
                End If
            Else
                If Not (txtDiscription.Text = gvTranOfMonth.Rows(gvTranOfMonth.SelectedIndex).Cells(2).Text) Then
                    If (qryPro.ToList.Count > 0) Then
                        Check = True
                    End If
                End If
            End If
            clsDataTable = Nothing
            sAmountEntity.Dispose()
            sAmountEntity = Nothing
        Catch ex As Exception
            WriteError(ex, "CheckDup", "sAmount")

        End Try
        Return Check
    End Function

    Private Function GetSortDirection(ByVal column As String) As String

        ' By default, set the sort direction to ascending.
        Dim sortDirection = "DESC"

        ' Retrieve the last column that was sorted.
        Dim sortExpression = TryCast(ViewState("SortExpression"), String)

        If sortExpression IsNot Nothing Then
            ' Check if the same column is being sorted.
            ' Otherwise, the default value can be returned.
            If sortExpression = column Then
                Dim lastDirection = TryCast(ViewState("SortDirection"), String)
                If lastDirection IsNot Nothing _
                  AndAlso lastDirection = "DESC" Then

                    sortDirection = "ASC"

                End If
            End If
        End If

        ' Save new values in ViewState.
        ViewState("SortDirection") = sortDirection
        ViewState("SortExpression") = column
        Return sortDirection
    End Function

    Private Sub setButton(ByVal button As Integer)

        If button = 1 Then 'unselect
            lblMsg.Visible = False

            btnModify.Enabled = False
            btnDelete.Enabled = False

            btnSearch.Enabled = True
            btnAdd.Enabled = True

            txtSEQ.Enabled = True

        ElseIf button = 2 Then 'select

            btnSearch.Enabled = False
            btnAdd.Enabled = False

            btnModify.Enabled = True
            btnDelete.Enabled = True

            txtSEQ.Enabled = False

        End If

    End Sub
    Public Sub clear()
        gvTranOfMonth.SelectedIndex = -1
        gvTranOfMonth.Visible = False
        setButton(1)
        lblMsg.Visible = False
        ddlProduct.SelectedIndex = 0
        rbtACTIVE.Checked = False
        rbtDeACTIVE.Checked = False
        txtSEQ.Text = ""
        txtDiscription.Text = ""
        lblTotal.Text = ""
        btnModify.Text = "แก้ไข"
        ddlProduct.Enabled = True
        txtSEQ.Enabled = True
    End Sub

    Private Sub reset()
        'gvUserRight.DataSource = dsUserRight.Tables("sUserRight")
        'gvUserRight.DataBind()
        ddlProduct.Value = ""
        'loadDataToDropDown()
        lblTotal.Text = ""
        rbtACTIVE.Checked = False
        rbtDeACTIVE.Checked = False
        setButton(1)
        lblMsg.Visible = False
        txtSEQ.Text = ""
        txtDiscription.Text = ""
        ddlProduct.Enabled = True
        txtSEQ.Enabled = True
    End Sub

    Private Function chkBeforeSave(ByVal chkModifly As Boolean) As Boolean
        Dim result As Boolean = True

        If (txtSEQ.Text = "") Then
            result = False
            strMsg = strMsg & "กรุณาระบุลำดับที่ต้องการ" & "\n"
            'ElseIf txtSEQ.Text.Length < 2 Then
            '    result = False
            '    strMsg = strMsg & "กรุณาระบุรหัสอำเภอมากกว่าหนึ่งหลัก" & "\n"
        ElseIf IsNumeric(txtSEQ.Text) = False Then
            result = False
            strMsg = strMsg & "กรุณาระบุรหัสอำเภอป็นตัวเลข" & "\n"
        End If


        If (txtDiscription.Text = "") Then
            result = False
            strMsg = strMsg & txtDiscription.Text & " : " & "กรุณาระบุรายละเอียด" & "\n"

        End If
        If (ddlProduct.Text = "") Then
            result = False
            strMsg = strMsg & txtDiscription.Text & " : " & "กรุณาระบุชื่อผลิตภัณฑ์" & "\n"

        End If

        If (CheckDupplication(chkModifly)) Then
            result = False
            strMsg = strMsg & txtDiscription.Text & " : " & "ระบุชื่ออำเภอซ้ำ" & "\n"
        End If
        If (rbtACTIVE.Checked = False And rbtDeACTIVE.Checked = False) Then
            result = False
            strMsg = strMsg & "กรุณาระบุสถานะการใช้ข้อมูล" & "\n"
        End If
        Return result

    End Function

    Private Sub SaveLogSearch()
        Try


            Dim desc As String = ""

            If Not (txtSEQ.Text = "") Then
                desc += " รหัสอำเภอ - " + txtSEQ.Text
            End If

            If Not (txtDiscription.Text = "") Then
                desc += " ชื่ออำเภอ - " + txtDiscription.Text
            End If


            If Not desc = "" Then
                desc = "ค้นหาข้อมูลอำเภอ จาก " + desc
            Else
                desc = "ค้นหาทั้งหมด"
            End If

            Dim clsLogTransaction As New clsLogTransaction
            clsLogTransaction.saveLogTransaction("", clsSessionMenuRight.getUserName, 1, desc, "M75")
            clsLogTransaction = Nothing
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Private Sub SaveLogPrint()
        Try

            Dim desc As String = "พิมพ์ข้อมูลอำเภอ"

            Dim clsLogTransaction As New clsLogTransaction
            clsLogTransaction.saveLogTransaction("", clsSessionMenuRight.getUserName, 2, desc, "M75")
            clsLogTransaction = Nothing
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Private Sub SaveLogNew()
        Try

            Dim desc As String = "บันทึก ข้อมูลอำเภอ (รหัสอำเภอ " + txtSEQ.Text + ")"

            Dim clsLogTransaction As New clsLogTransaction
            clsLogTransaction.saveLogTransaction(txtSEQ.Text, clsSessionMenuRight.getUserName, 3, desc, "M75")
            clsLogTransaction = Nothing
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Private Sub SaveLogEdit()
        Try

            Dim desc As String = "บันทึก แก้ไข ข้อมูลอำเภอ (รหัสอำเภอ " + txtSEQ.Text + ")"

            Dim clsLogTransaction As New clsLogTransaction
            clsLogTransaction.saveLogTransaction(txtSEQ.Text, clsSessionMenuRight.getUserName, 4, desc, "M75")
            clsLogTransaction = Nothing
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    'Private Function SetStatusChilds(ByVal status As String, ByVal refcode As String, ByVal entity As KYCEntities) As Boolean
    '    Dim childs As List(Of REFERENCE_CODE_TABLE) = (From Amount In entity.REFERENCE_CODE_TABLE
    '                     Where Amount.SEQ.StartsWith(refcode)).ToList
    '    For Each ss As REFERENCE_CODE_TABLE In childs
    '        ss.ACTIVE = status
    '    Next
    '    Return True
    'End Function

    Private Sub SaveLogDelete(ByVal value As String)
        Try

            Dim desc As String = "ลบข้อมูลอำเภอ (รหัสอำเภอ " + value + ")"

            Dim clsLogTransaction As New clsLogTransaction
            clsLogTransaction.saveLogTransaction(value, clsSessionMenuRight.getUserName, 5, desc, "M75")
            clsLogTransaction = Nothing
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Public Sub loadDataToDropDown()
        Try
            Dim items As New ListEditItem
            items.Value = 0
            items.Text = "ทั้งหมด"
            Dim db As New KYCEntities
            Dim selectDt = From i In db.MPRODUCT Select i.PRODUCTCODE, i.PRODUCTNAME Order By PRODUCTCODE Ascending
            ddlProduct.DataSource = selectDt.ToList()
            ddlProduct.ValueField = "PRODUCTCODE"
            ddlProduct.TextField = "PRODUCTNAME"
            ddlProduct.DataBind()
            ddlProduct.Items.Insert(0, items)
            ddlProduct.Dispose()
            ddlProduct.SelectedIndex = 0
        Catch ex As Exception
            Throw ex
        End Try
    End Sub


#End Region

End Class
